package com.scalar.chiptrack.jasper.engineering.dataproviders;

import net.sf.jasperreports.engine.data.JRAbstractBeanDataSourceProvider;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import net.sf.jasperreports.engine.*;
import com.scalar.chiptrack.jasper.engineering.beans.BinYieldData;

import java.util.ArrayList;

/**
 * User: sujan
 * Date: Apr 3, 2011
 * Time: 8:01:27 PM
 */
public class YieldBinGraphDataSourceProvider extends JRAbstractBeanDataSourceProvider {

	public YieldBinGraphDataSourceProvider() {
		super(BinYieldData.class);
	}

	public JRField[] getFields(JasperReport report) throws JRException {

		if (report != null) {
			System.out.println(report);
			JRParameter[] params = report.getParameters();
			for (int i = 0; i < params.length; ++i) {
				System.out.println(params[i].getName() + " "
						+ params[i].getDefaultValueExpression());
			}

			String[] properties = report.getPropertyNames();
			for (int i = 0; i < properties.length; ++i) {
				System.out.println(properties[i] + " = "
						+ report.getProperty(properties[i]));
			}
		}
		return super.getFields(report);
	}


	public JRDataSource create(JasperReport report) throws JRException {
		if (report != null) {
			System.out.println(report);
			JRParameter[] params = report.getParameters();
			for (int i = 0; i < params.length; ++i) {
				System.out.println(params[i].getName() + " "
						+ params[i].getDefaultValueExpression());
			}

			String[] properties = report.getPropertyNames();
			for (int i = 0; i < properties.length; ++i) {
				System.out.println(properties[i] + " = "
						+ report.getProperty(properties[i]));
			}
		}
		ArrayList list = new ArrayList();
		list.add(new BinYieldData("Bin 1", 100));
		list.add(new BinYieldData("Bin 2", 40));
		list.add(new BinYieldData("Bin 3", 70));
		list.add(new BinYieldData("Bin 4", 90));
		list.add(new BinYieldData("Bin 5", 20));
		return new JRBeanCollectionDataSource(list);
	}

	public void dispose(JRDataSource dataSource) throws JRException {
		// nothing to do
	}
}
